package com.foruo.sc.upload.file.example;

import com.foruo.sc.upload.file.client.DeleteClient;
import com.foruo.sc.upload.file.client.UploadWithByteClient;
import com.foruo.sc.upload.file.client.UploadWithFileClient;
import com.foruo.sc.upload.file.client.UploadWithStreamClient;
import com.foruo.sc.upload.file.util.FileConvertUtil;
import com.foruo.sc.upload.file.util.UUIDUtils;
import org.apache.commons.lang3.time.DateFormatUtils;

import java.io.File;
import java.util.Date;
/**
 * 案例
 * @author GaoYuan
 * @date 2018/4/11 上午10:49
 */
public class UploadFileExample {

    public static void main(String[] args){
//        //代码测试上传
        /** 文件字节流 */
        UploadWithByteClient.upload("http://127.0.0.1:10009/file/upload", FileConvertUtil.fileToByte(new File("/Users/gy/Downloads/cxyy.png")), DateFormatUtils.format(new Date(), "yyyyMMdd") + File.separator + UUIDUtils.getUUIDNoCross() + ".png");
        /** 文件字符流 */
        UploadWithStreamClient.upload("http://127.0.0.1:10009/file/upload", FileConvertUtil.fileToInputStream(new File("/Users/gy/Downloads/cxyy.png")),DateFormatUtils.format(new Date(), "yyyyMMdd") + File.separator + UUIDUtils.getUUIDNoCross() + ".png");
        /** 文件 */
        UploadWithFileClient.upload("http://127.0.0.1:10009/file/upload",new File("/Users/gy/Downloads/cxyy.png"),DateFormatUtils.format(new Date(), "yyyyMMdd") + File.separator + UUIDUtils.getUUIDNoCross() + ".png");
//        //浏览器测试读取
        /** 测试删除文件 */
        DeleteClient.delete("http://127.0.0.1:10009/file/delete","a/20180410/f1d4a9a199024d19aa49e902f59fff40.png");
    }
}
